package com.thoughtworks;

import java.util.*;

public class Helper {
    public static String convert2String(List<String> list){
        StringBuilder str = new StringBuilder();
        for(String s: list){
            str.append(s);
        }
        return str+"";
    }

    public static ArrayList<String> convert2ArrayList(String input){
        String[] input2 = input.split("");
        ArrayList<String> list = new ArrayList<>();
        for(String s: input2){
            list.add(s);
        }
        return list;
    }

    public static Boolean containSame(String guess){
        String[] guess2 = guess.split("");
        ArrayList<String> guess3 = new ArrayList<>();
        for(String s: guess2){
            if(guess3.contains(s)){
                return true;
            }else {
                guess3.add(s);
            }
        }
        return false;
    }

    public static Boolean isRepeat(String guess) {
        Set<String> unRepeatSet = new HashSet<>();
        for(String s: guess.split("")){
            boolean ifRepeat = unRepeatSet.add(s);
            if(!ifRepeat){
                return true;
            }
        }
        return false;
    }

    public static List<String> createRandomAnswer(){
        String answer = "";
        Random rd = new Random();
        List<String> list = new ArrayList<>();
        int i=0;
        while(i<4){
            int num = rd.nextInt(10);
            if(!list.contains(String.valueOf(num))){
                list.add(String.valueOf(num));
                i += 1;
            }
        }
        return list;
    }
}
